package com.biboheart.adapter.express.support;

import com.biboheart.adapter.express.actuator.GenericActuator;
import com.biboheart.adapter.support.utils.ObjectTypeUtils;

final class BinaryActuator implements GenericActuator {
    @Override
    public Object execute(Object source, Object... args) {
        if (null == source || args.length == 0) {
            return source;
        }
        long number = ObjectTypeUtils.convertType(source, Long.class);
        int digit = ObjectTypeUtils.convertType(args[0], Integer.class);
        Long set = args.length > 1 ? ObjectTypeUtils.convertType(args[1], Long.class) : null;
        if (null == set) {
            return (number >> digit) & 1;
        } else {
            return number | (set << digit);
        }
    }
}
